fix: guard validate_unique against unsaved Release in admin add view#2940
Merged
JacobCoffee merged 1 commit intomainfrom Feb 23, 2026
Merged
fix: guard validate_unique against unsaved Release in admin add view#2940JacobCoffee merged 1 commit intomainfrom
JacobCoffee merged 1 commit intomainfrom
Conversation
Django 5.2 raises ValueError when unsaved model instances are passed to related filters. The ReleaseFile.validate_unique() method filters by release=self.release, which fails on the admin add view because the parent Release hasn't been saved yet (no PK). Adding a self.release_id check skips the query for unsaved releases, which is safe since no conflicting records can exist for a release that isn't in the database yet. Fixes 500 error on POST /admin/downloads/release/add/ when creating a new release with download_button enabled on inline release files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug introduced by Django 5.2 where creating a Release with inline ReleaseFiles in the admin interface would fail with a ValueError. Django 5.2 (deployed Feb 6 via #2741) added stricter validation that prevents unsaved model instances from being used in queryset filters. The ReleaseFile.validate_unique() method was filtering by release=self.release, which failed when the parent Release hadn't been saved yet during admin add operations.
Changes:
- Added a guard condition to check
self.release_idbefore running the uniqueness query inReleaseFile.validate_unique() - This prevents the ValueError while maintaining validation for saved releases
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
JacobCoffee
commented
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ValueError("Model instances passed to related filters must be saved.")when unsaved model instances are used in queryset filtersReleaseFile.validate_unique()filters byrelease=self.release, which fails on the admin add view because the parentReleasehasn't been saved yet (no PK)and self.release_idskips the uniqueness query for unsaved releases — safe because no conflicting records can exist for a release not yet in the databaseContext
Steve Dower hit this today trying to create the "Python install manager 26.0" release via
/admin/downloads/release/add/with an inline MSIX release file that haddownload_button=True. Got 500 errors 3 times.Sentry event:
d05ec42eb5a44cceb69616c057186471The
validate_uniquewas added in #2137 (Sept 2022) and worked fine until the Django 5.2 upgrade tightened related filter validation.Workaround (until this is deployed): create the release without release files or with
download_buttonunchecked, save, then edit to add them.Test plan
/admin/downloads/release/add/with an inline release file that hasdownload_button=True— should save successfullydownload_button— uniqueness validation should still fire correctly🤖 Generated with Claude Code